package it.tukano.beanstore;

import it.tukano.check.Todo;
import java.io.File;

/**
 * A factory for BeanStore instances
 * @author pgi
 */
public class BeanStoreFactory {

    /**
     * Instance initializer
     */
    public BeanStoreFactory() {
    }

    /**
     * Creates a new bean store with the given id.
     * @param id the id of the bean store to load
     * @return the bean store for the given id
     */
    public BeanStore newBeanStore(String id) {
        File file = new File(System.getProperty("user.home"), id);
        if(!file.exists()) file.mkdir();
        return new FileBeanStore(file);
    }

    /**
     * Creates a new bean store using the given folder as base
     * @param folder the folder to use as base
     * @return the bean store that uses the given folder as base
     */
    public BeanStore newBeanStore(File folder) {
        if(!folder.exists()) {
            folder.mkdirs();            
        }
        return new FileBeanStore(folder);
    }

    /**
     * returns or create and returns the bean store with the given name in the
     * given folder
     * @param base the base folder of the bean store
     * @param name the name of the bean store
     * @return the requested bean store.
     */
    public BeanStore newBeanStore(File base, String name) {
        File folder = new File(base, name);
        return newBeanStore(folder);
    }
}
